package com.maple.excel.entity;

import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentStyle;
import com.alibaba.excel.annotation.write.style.HeadStyle;
import com.maple.excel.utils.LocalDateTimeConverter;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.springframework.beans.BeanUtils;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.util.Assert;

import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * <p>客户导出信息类</p>
 *
 * @author maple
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class CustomerExportDTO implements Serializable {

    private static final long serialVersionUID = 1L;

    @ColumnWidth(20)
    @ExcelProperty("姓名/昵称")
    private String name;

    @ColumnWidth(20)
    @ExcelProperty("性别")
    private String gender;

    @ColumnWidth(30)
    @ExcelProperty("电话")
    private String mobile;

    @ColumnWidth(30)
    @ExcelProperty(value = "添加时间")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;

    /**
     * 将Customer转换成Excel导出实体
     */
    public static CustomerExportDTO format(@NotNull Customer customer) {
        Assert.notNull(customer, "customer is required");
        CustomerExportDTO dto = new CustomerExportDTO();
        BeanUtils.copyProperties(customer, dto);

        //处理客户的性别 0-未知 1-男性 2-女性
        Integer gender = customer.getGender();
        dto.setGender(gender == 1 ? "男" : (gender == 2 ? "女性" : "未知"));
        return dto;
    }
}
